<%@page import="com.qdu.entity.Log"%>
<%@page import="com.qdu.entity.Log"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
        <script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
        <link rel="stylesheet" href="css/managerStyle.css"/>
        <title>日志表格</title>
        <style>
            table tr th{
                background-color: darkcyan;
                color: white;
                text-align: center;
            }
            #in{
                white-space:nowrap;
                overflow:hidden;
                text-overflow: ellipsis;
                width: 50px;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <br>
            <table id="dataTable" class="table table-hover table-striped">
                <tr>
                    <th>日志编号</th>
                    <th>日志名称</th>
                    <th>活动编号</th>
                    <th>用户编号</th>
                    <th>日志内容</th>
                    <th>日志图片</th>
                    <th>发表时间</th>
                    <th>点赞数量</th>
                    <th>操作</th>
                </tr>
                <%
                //从请求对象中根据属性名studentList获取属性值，属性值是一个List<Student>对象
                List<Log> list = (List<Log>) request.getAttribute("logList");

                //如果学生列表为空，则没必要执行后续代码，直接返回即可
                if (null == list || list.size() == 0) {
                    return;
                }else{
                //如果列表不为空，则会执行if后面的代码，显示学生列表
                    //循环遍历列表
                    for (Log i:list) {
                %>
                <!--循环显示-->
                    <tr id="tr<%=i.getId()%>">
                        <td id="no"><a href="msols?id=<%=i.getId()%>"><%=i.getId()%></a></td>
                        <td><%=i.getName() %></td>
                        <td><%=i.getActivityId() %></td>
                        <td><%=i.getUserid() %></td>
                        <td><div class="in" title="<%=i.getContent() %>"><%=i.getContent() %></div></td>
                        <td><%=i.getImag() %></td>
                        <td><%=i.getTime() %></td>
                        <td><%=i.getAgree() %></td>
                        <td>
                            <!--点击超链接可执行js代码，需要添加前缀“javascript:”-->
                            <!--这里点击“删除”超链接调用自定义的deleteStudent()函数，传入学号删除当前学生-->
                            <!--因为学号是字符串，所以参数两端加引号（外围已经有双引号，所以用了单引号-->
                            <a href="javascript:deleteLog('<%=i.getId()%>')" id="delete">删除</a>
                        </td>
                    </tr>
                <%
                    }
                        }
                %>
            </table>
            <script>
            function deleteLog(id){
                 $.ajax({
                     url:"dols",
                     type:"GET",
                     data: {logId:id},
                     success:function(){
                         $("#tr"+id).remove();
                     },
                     error:function (req, status, error) { 
                        alert("请求处理出错，错误信息：" + error);
                    }
                 }); 
            }
        </script>
    </body>
</html>
